package com.g8.pethospitallearnbackend.controller;

import com.g8.pethospitallearnbackend.entity.Question;
import com.g8.pethospitallearnbackend.entity.UserForLogin;
import com.g8.pethospitallearnbackend.exception.CustomException;
import com.g8.pethospitallearnbackend.service.QuestionService;
import com.g8.pethospitallearnbackend.utils.responseUtil.ResponseStatusEnum;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/question")
public class QuestionController {

    @Autowired
    QuestionService questionService;
    private String quesId;

    @GetMapping
    public List<Question> getAllQues(){
        List<Question> questions = questionService.getAllQusetions();
        return questions;
    }

    @RequestMapping("/{quesId}")
    public Question getQuesById(@PathVariable("quesId") String quesId){
        Question question = questionService.getQuesById(quesId);
        return question;
    }

    @RequestMapping("/searchques")
    public List<Question> searchQues(@RequestParam("searchQues") String searchQues){
        List<Question> questions = questionService.searchQues(searchQues);
        return questions;
    }

    @RequestMapping("/questype")
    public List<Question> selectByType(@RequestParam("typeName") String typeName){
        List<Question> questions = questionService.selectByType(typeName);
        return questions;
    }

    @PostMapping
    public Question addQues(@RequestBody Question question){
        return questionService.addQues(question);
    }

    @PutMapping
    public Question changeQues(@RequestBody Question question){
        return questionService.changeQues(question);
    }

    @DeleteMapping("/{quesId}")
    public void deleteQues(@PathVariable("quesId") String quesId){
        questionService.deleteQues(quesId);
    }

}
